Report post

Is pub mod overrused?

struct Bar {z: PhantomData } I strongly believe that pub mod is overrused. By keeping most modules private and using pub use to expose a flatter heirarchy (a.k.a. the facade pattern), you: Make the public API easier to learn and use. Make it easier to move things to other places while refactoring without breaking the public API.

Is pub mod Path m2 valid rust?

pub mod path::m2 is not valid Rust. mod foo; is akin to copying and pasting a module into the current scope. That is, if the current scope can find module foo at its own "top level" — basically, if there's a file foo.rs or a folder foo in the same directory — then mod foo; basically gets transformed into mod foo { /* contents of foo */ }.

What is the difference between pub use and pub mod?

There may be circumstances where one could use either pub use or pub mod, though they'd be contrived and in any case where both could work one should prefer the former (see third point below). The key differences are: pub use is followed by a path (a bare identifier m2 would be the same as self::m2 ). pub mod is only followed by an identifier.

Related articles

The World's Leading Crypto Trading Platform

Get my welcome gifts